package com.zjl.学习.第06章_块步骤_读操作写.A_ItemReader块读;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zjl.学习.第06章_块步骤_读操作写.User;
import org.springframework.batch.item.json.JacksonJsonObjectReader;
import org.springframework.batch.item.json.builder.JsonItemReaderBuilder;
import org.springframework.core.io.ClassPathResource;

/**
 * Spring Batch 也提供专门操作Json文档的API ： JsonItemReader，具体使用且看案例
 */
public class A3_json读取 {
    public static void main(String[] args) {
        ObjectMapper objectMapper = new ObjectMapper();
        JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);
        jsonObjectReader.setMapper(objectMapper);

        new JsonItemReaderBuilder<User>()
                .name("userJsonItemReader")
                .jsonObjectReader(jsonObjectReader)
                .resource(new ClassPathResource("item/user.json"))
                .build();
    }

}
